<?php
session_start();
include '../connectBDD.php';

if (isset($_GET['id_event'])) {
    $idEvent = $_GET['id_event'];
    $query = "SELECT c.id_comment, c.comment, c.login, c.dateTime, u.avatar_path FROM comments c, user u WHERE c.login = u.login and c.id_event = $idEvent ORDER BY c.dateTime desc";
    $result3 = mysql_query($query);
    if (!$result3) {
        echo mysql_error();
    }
    $nb_res = mysql_num_rows($result3);
    if ($nb_res > 0) {

        while ($rows = mysql_fetch_assoc($result3)) {
            echo"
                         <div class='commentaire'>
                            <div id='petite_image'>
                                <img src=" . $rows['avatar_path'] . " width='50px' height='50px' />
                            </div>";
            if (isset($_SESSION['login']) && $_SESSION['login'] == $rows['login']) {
                echo "<a class='croix_ferm' href=\"javascript:supprimerCommentaire('" . $rows['id_comment'] . "', $idEvent, 'utilisateur')\"><img src='images/picto_croix.gif'/></a>";
            }
            echo"<div id='blockLoginMP'>
                                <div id='login_msg'>
                                    <a href='profil.php?login=" . $rows['login'] . "'>" . $rows['login'] . "</a>
                                     <span class='heure_msg'>" . date_format(new DateTime($rows['dateTime']), 'd/m/Y à H:i:s') . "</span>
                                </div>
                                
                            </div><br style='clear:both'/>
                            <div id='comment_content'><p>" . $rows['comment'] . "</p></div>
                        </div>";
        }
    }
    
}
    ?>